package com.svs.web.controller.test;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class DelayElement implements Delayed{
	
	private long now;
	
	private long expireTime;
	
	private Long activityId;
	
	private Integer state;
	
	private Integer beforeState;
	
	@Override
    public long getDelay(TimeUnit unit) {
        //判断是否过期
        return unit.convert(expireTime-System.currentTimeMillis(),TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed delayed) {
        //排序规则：按照过期时间排序
        DelayElement that = (DelayElement)delayed;
        if (this.expireTime<that.expireTime){
            return -1;
        }else if (this.expireTime>that.expireTime){
            return 1;
        }else {
            return 0;
        }
    }

	public long getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(long expireTime) {
		this.expireTime = expireTime;
	}

	public Long getActivityId() {
		return activityId;
	}

	public void setActivityId(Long activityId) {
		this.activityId = activityId;
	}

	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public Integer getBeforeState() {
		return beforeState;
	}

	public void setBeforeState(Integer beforeState) {
		this.beforeState = beforeState;
	}

	public long getNow() {
		return now;
	}

	public void setNow(long now) {
		this.now = now;
	}
    
}
